import reshandler from 'services/response-handler'
import getLocation from "services/get-location";

/*
 * 查询推荐服务列表
 */
function getTime() {
    var d = new Date();
    var yy = d.getFullYear();
    var mm = d.getMonth() + 1;
    var dd = d.getDate();
    var hh = d.getHours();
    var MM = d.getMinutes();
    var ss = d.getSeconds();
    var time = yy + "-" + (mm > 9 ? mm : '0' + mm) + "-" + (dd > 9 ? dd : '0' + dd) + " " + hh + ":" + MM + ":" + ss;
    return time
}
function makeData(response) {
    let nowTime = getTime();
    if (response.followList.length > 0) {
        for (let i = 0; i < response.followList.length; i++) {
            let services = ''
            let publishDate = response.followList[i].publishDate
            if (publishDate.substring(0, 10) === nowTime.substring(0, 10)) {
                response.followList[i].showTime = publishDate.substring(10, 16)
            } else if (publishDate.substring(0, 4) !== nowTime.substring(0, 4)) {
                response.followList[i].showTime = publishDate.substring(0, 10)
            } else {
                response.followList[i].showTime = publishDate.substring(5, 10)
            }
            for (let j = 0; j < response.followList[i].shop.specialServices.length; j++) {
                if (j != response.followList[i].shop.specialServices.length - 1) {
                    services = services + response.followList[i].shop.specialServices[j] + '|'
                } else {
                    services = services + response.followList[i].shop.specialServices[j]
                }
            }
            response.followList[i].shop.specialServices = services;
        }
    }
    return Object.assign({}, response.followList, {
    })
}
export default function (params, success, fail) {
    // request 
    params = Object.assign({}, params, {
        methodName: "ListRecommendFollow",
    })
    // invoke
    this.$.get(params).then(reshandler.success(success, fail, makeData), reshandler.error(fail))
}
